package cn.kooki.app.duobao.ui.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.kooki.app.duobao.R;
import cn.kooki.app.duobao.base.BaseRecyclerAdapter;
import cn.kooki.app.duobao.data.Bean.Index.GoodsItem;
import cn.kooki.app.duobao.util.StringUtils;

/**
 * Created by xiong on 2015/12/19.
 */
public class ListRecommAdapter extends BaseRecyclerAdapter<GoodsItem> {

    private final Context context;

    public ListRecommAdapter(Context context) {
        this.context = context;
    }


    @Override
    public RecyclerView.ViewHolder onCreate(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_recommend_item, parent, false);
        return new RecoomViewHolder(view);
    }

    @Override
    public void onBind(RecyclerView.ViewHolder viewHolder, int RealPosition, GoodsItem data) {
        RecoomViewHolder recoomViewHolder = (RecoomViewHolder) viewHolder;
        recoomViewHolder.goodsName.setText(data.getTitle());

        int total = StringUtils.nullSafeParseInt(data.getZongrenshu());
        int currt = StringUtils.nullSafeParseInt(data.getCanyurenshu());

        recoomViewHolder.goodsProgress.setMax(total);
        recoomViewHolder.goodsProgress.setProgress(currt);
        Glide.with(context).load(data.getThumb()).placeholder(R.drawable.img_blank)
                .into(recoomViewHolder.goodsImg);
    }

    public class RecoomViewHolder extends RecyclerView.ViewHolder {


        @Bind(R.id.goods_img)
        ImageView goodsImg;
        @Bind(R.id.goods_name)
        TextView goodsName;
        @Bind(R.id.goods_progress)
        ProgressBar goodsProgress;

        public RecoomViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }


    }
}
